package com.lyxs916.appbaselibrary.core.activity;

import android.os.Bundle;

import com.lyxs916.appbaselibrary.core.iview.BaseView;
import com.lyxs916.appbaselibrary.core.presenter.BasePresenter;


/**
 * 说明:BaseMvpActivity 的基类
 * 作者： 杨阳; 创建于：  2017-06-06  13:09
 */
public abstract class BaseMvpActivity<V extends BaseView, P extends BasePresenter<V>> extends BaseActivity {
    public P presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        presenter = initPresenter();

        if (presenter != null) {
            presenter.onCreate((V) this);
        }
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void onDestroy() {
        if (presenter != null) {
            presenter.onDestroy();
        }
        super.onDestroy();
    }

    @Override
    public void onLowMemory() {
        if (presenter != null) {
            presenter.onLowMemory();
        }
        super.onLowMemory();
    }

    /**
     * 获取presenter的实例
     *
     * @return
     */
    public abstract P initPresenter();
}
